home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_055 / vsprites / geltools.c next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  174 lines

  1. /****************************************************************************
  2.  *                                                                          *
  3.  *                              GELTOOLS                                    *
  4.  *      (c) 1986 Commodore-Amiga, Inc.                                      *
  5.  ****************************************************************************/
  6.  
  7. #include "vsprite.h"            /* standard includes & definitions */
  8.  
  9.  
  10. /* ======================================================================== */
  11. /* ==== PrepGels ========================================================== */
  12. /* ======================================================================== */
  13.  
  14. MakeGelsInfo(rp, reserve)
  15. struct RastPort *rp;
  16. BYTE reserve;
  17. {
  18.     struct GelsInfo *g;
  19.     struct VSprite *HeadSprite, *TailSprite;
  20.  
  21.     g = (struct GelsInfo *)AllocMem(sizeof(struct GelsInfo),
  22.         MEMF_PUBLIC | MEMF_CLEAR);
  23.     rp->GelsInfo = g;
  24.  
  25.     g->sprRsrvd = reserve;
  26.     g->nextLine = (WORD *)AllocMem(8 * sizeof(WORD),
  27.         MEMF_PUBLIC | MEMF_CLEAR);
  28.     g->lastColor = (WORD *)AllocMem(8 * sizeof(LONG),
  29.         MEMF_PUBLIC | MEMF_CLEAR);
  30.     g->collHandler = (struct collTable *)AllocMem(sizeof(struct collTable),
  31.         MEMF_PUBLIC | MEMF_CLEAR);
  32.     g->leftmost = 0;
  33.     g->rightmost = rp->BitMap->BytesPerRow * 8 - 1;
  34.     g->topmost = 0;
  35.     g->bottommost = rp->BitMap->Rows - 1;
  36.  
  37.     HeadSprite = (struct VSprite *)AllocMem(sizeof(struct VSprite),
  38.         MEMF_PUBLIC | MEMF_CLEAR);
  39.     TailSprite = (struct VSprite *)AllocMem(sizeof(struct VSprite),
  40.         MEMF_PUBLIC | MEMF_CLEAR);
  41.     InitGels(HeadSprite, TailSprite, g);
  42. }
  43.  
  44.  
  45. /* ======================================================================== */
  46. /* ==== DeleteGelsInfo ==================================================== */
  47. /* ======================================================================== */
  48.  
  49. DeleteGelsInfo(g)
  50. struct GelsInfo *g;
  51. {
  52.     if(g)
  53.     {
  54.         if(g->nextLine)FreeMem(g->nextLine, 8 * sizeof(WORD));
  55.         if(g->lastColor)FreeMem(g->lastColor, 8 * sizeof(LONG));
  56.         if(g->collHandler)FreeMem(g->collHandler, sizeof(struct collTable));
  57.         if(g->gelHead)FreeMem(g->gelHead, sizeof(struct VSprite));
  58.         if(g->gelTail)FreeMem(g->gelTail, sizeof(struct VSprite));
  59.  
  60.         FreeMem(g, sizeof(struct GelsInfo));
  61.     }
  62. }
  63.  
  64.  
  65. /* ======================================================================== */
  66. /* ==== MakeVSprite ======================================================= */
  67. /* ======================================================================== */
  68.  
  69. struct VSprite *
  70. MakeVSprite(x, y, vsheight, vswidth, vsdepth, vsimage, vscolors)
  71. WORD x, y;
  72. WORD vsheight, vswidth, vsdepth;
  73. WORD *vsimage;
  74. WORD *vscolors;
  75. {
  76.     WORD i;
  77.     struct VSprite *vs;
  78.  
  79.     vs = (struct VSprite *)AllocMem(sizeof(struct VSprite),
  80.         MEMF_PUBLIC | MEMF_CLEAR);
  81.  
  82.     vs->Flags = VSPRITE;
  83.     vs->X = x;
  84.     vs->Y = y;
  85.     vs->Height = vsheight;
  86.     vs->Width = vswidth;
  87.     vs->Depth = vsdepth;
  88.     vs->ImageData = (WORD *)AllocMem(vsheight * vswidth * vsdepth *
  89.         sizeof(WORD), MEMF_CHIP);
  90.     for(i = 0; i < (vsheight * vswidth * vsdepth); i++)
  91.         vs->ImageData[i] = vsimage[i];
  92.  
  93.     vs->SprColors = vscolors;
  94.  
  95.     return(vs);
  96. }
  97.  
  98.  
  99. /* ======================================================================== */
  100. /* ==== DeleteVSprite ===================================================== */
  101. /* ======================================================================== */
  102.  
  103. DeleteVSprite(vs, pfdepth)
  104. struct VSprite *vs;
  105. WORD pfdepth;
  106. {
  107.     if(vs)
  108.     {
  109.         if(vs->VSBob)
  110.         {
  111.             RemBob(vs->VSBob);
  112.             if(vs->VSBob->SaveBuffer)FreeMem(vs->VSBob->SaveBuffer,
  113.                 vs->Height * vs->Width * pfdepth * sizeof(WORD));
  114.             FreeMem(vs->VSBob, sizeof(struct Bob));
  115.         }
  116.  
  117.         RemVSprite(vs);
  118.  
  119.         if(vs->ImageData)FreeMem(vs->ImageData,
  120.             vs->Height * vs->Width * vs->Depth * sizeof(WORD));
  121.         if(vs->BorderLine)FreeMem(vs->BorderLine,
  122.             vs->Width * sizeof(WORD));
  123.         if(vs->CollMask) FreeMem(vs->CollMask,
  124.             vs->Height * vs->Width * sizeof(WORD));
  125.  
  126.         FreeMem(vs, sizeof(struct VSprite));
  127.     }
  128. }
  129.  
  130.  
  131. /* ======================================================================== */
  132. /* ==== MakeBob =========================================================== */
  133. /* ======================================================================== */
  134.  
  135. struct VSprite *
  136. MakeBob(x, y, bheight, bwidth, bdepth, bimage, pfdepth, pp, poo)
  137. WORD x, y;
  138. WORD bheight, bwidth, bdepth;
  139. WORD *bimage;
  140. WORD pfdepth;
  141. BYTE pp, poo;
  142. {
  143.     struct Bob *b;
  144.     struct VSprite *v;
  145.  
  146.     v = MakeVSprite(x, y, bheight, bwidth, bdepth, bimage, NULL);
  147.     b = (struct Bob *)AllocMem(sizeof(struct Bob),
  148.         MEMF_PUBLIC | MEMF_CLEAR);
  149.     v->VSBob = b;
  150.     b->BobVSprite = v;
  151.  
  152.     v->PlanePick = pp;
  153.     v->PlaneOnOff = poo;
  154.     v->Flags = OVERLAY | SAVEBACK;
  155.  
  156.     v->BorderLine = (WORD *)AllocMem((bwidth * sizeof(WORD)),
  157.         MEMF_PUBLIC | MEMF_CLEAR);
  158.     v->CollMask = (WORD *)AllocMem((sizeof(WORD) * bheight * bwidth),
  159.         MEMF_CHIP | MEMF_CLEAR);
  160.  
  161.     b->SaveBuffer = (WORD *)AllocMem(bheight * bwidth * pfdepth *
  162.         sizeof(WORD), MEMF_CHIP | MEMF_CLEAR);
  163.     b->ImageShadow = v->CollMask;
  164.  
  165.     InitMasks(v);
  166.  
  167.     return(v);
  168. }
  169.  
  170.  
  171. /* =========================== END OF FILE ================================ */
  172.  
  173.  
  174.